﻿Imports System.Data.SqlClient

Public Class clsPermisos
    Private mintIdPermiso As Integer
    Private mintidEmpleado As Integer
    Private mdatDia As Date
    Private mstrHorario As String
    Private mstrTipo As String
    Private mstrObservaciones As String
    Private mstrCapturo As String
    Private mstrReportado As String
    Public Property idPermiso() As Integer
        Get
            Return mintIdPermiso
        End Get
        Set(ByVal value As Integer)
            mintIdPermiso = value
        End Set
    End Property

    Public Property idempleado() As Integer
        Get
            Return mintidEmpleado
        End Get
        Set(ByVal value As Integer)
            mintidEmpleado = value
        End Set
    End Property
    Public Property Dia() As Date
        Get
            Return mdatDia
        End Get
        Set(ByVal value As Date)
            mdatDia = value
        End Set
    End Property

    Public Property Horario() As String
        Get
            Return mstrHorario
        End Get
        Set(ByVal value As String)
            mstrHorario = value
        End Set
    End Property
    Public Property Tipo() As String
        Get
            Return mstrTipo
        End Get
        Set(ByVal value As String)
            mstrTipo = value
        End Set
    End Property
    Public Property Observaciones() As String
        Get
            Return mstrObservaciones
        End Get
        Set(ByVal value As String)
            mstrObservaciones = value
        End Set
    End Property
    Public Property Capturo() As String
        Get
            Return mstrCapturo
        End Get
        Set(ByVal value As String)
            mstrCapturo = value
        End Set
    End Property
    Public Property Reportado() As String
        Get
            Return mstrReportado
        End Get
        Set(ByVal value As String)
            mstrReportado = value
        End Set
    End Property
    Public Sub New()
        mintIdPermiso = 0
        mintidEmpleado = 0
        mdatDia = Now()
        mstrHorario = ""
        mstrTipo = ""
        mstrObservaciones = ""
        mstrCapturo = ""
        mstrReportado = ""


    End Sub
    Public Sub Borrar()
        Call SetSqlCitra("Delete From Permisos Where idEmpleado = " & idempleado)

    End Sub
    Public Sub Buscar()
        Dim cnConn As New sqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Permisos " & _
        " WHERE idEmpleado=" & idempleado

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mintIdPermiso = rdBuscar("idPermiso")
            mintidEmpleado = rdBuscar("idempleado")
            mdatDia = rdBuscar("Dia")
            mstrHorario = rdBuscar("horario").ToString.Trim
            mstrTipo = rdBuscar("tipo").ToString.Trim
            mstrObservaciones = rdBuscar("observacio").ToString.Trim
            mstrCapturo = rdBuscar("capturo").ToString.Trim
            mstrReportado = rdBuscar("reportado").ToString.Trim
        Else
            mintIdPermiso = 0
            mintidEmpleado = 0
            mdatDia = Now()
            mstrHorario = ""
            mstrTipo = ""
            mstrObservaciones = ""
            mstrCapturo = ""
            mstrReportado = ""
        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Permisos (" & _
                            "IdPermiso," & _
                            "IdEmpleado," & _
                            "Dia," & _
                            "Horario," & _
                            "Tipo," & _
                            "Observaciones," & _
                            "Capturo," & _
                            "Reportado)" & _
                            "VALUES (" & _
                            "@IdPermiso," & _
                            "@IdEmpleado," & _
                            "@Dia," & _
                            "@Horario," & _
                            "@Tipo," & _
                            "@Observaciones," & _
                            "@Capturo," & _
                            "@Reportado)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdPermiso", mintIdPermiso)
        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("Dia", mdatDia)
        Command.Parameters.AddWithValue("Horario", mstrHorario)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
        Command.Parameters.AddWithValue("Observaciones", mstrObservaciones)
        Command.Parameters.AddWithValue("Capturo", mstrCapturo)
        Command.Parameters.AddWithValue("Reportado", mstrReportado)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el permiso", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
